﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Noris.Schedule.Support;
using Noris.Schedule.Support.Parser;
using System.Drawing;
using Noris.Tools.FrxEditor.Components;

namespace Noris.Tools.FrxEditor.Data
{
    /// <summary>
    /// Třída, která zajišťuje konverzi z formátu Powerbuilder
    /// </summary>
    internal class Pb7Loader : IDisposable
    {
        #region Načítání obsahu reportu z formátu PowerBuilder.SRD
        /// <summary>
        /// Načte a vrátí data z dodaného stringu, data jsou parsovaná na jednotlivé prvky dle formátu SRD.
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        internal static List<ParserSegment> GetReportSrdDataFromContent(string content)
        {
            if (content == null) return null;

            List<ParserSegment> srdList = Parser.ParseString(content, CreateParserSettingSrd());
            return srdList;
        }
        /// <summary>
        /// Načte a vrátí data ze souboru daného jména, data jsou parsovaná na jednotlivé prvky dle formátu SRD.
        /// Soubor hledá a načítá metodou GetReportSrd(): Hledá nejbližší adresář Reports, a v něm (i v jeho podadresářích) hledá soubor daného jména.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static List<ParserSegment> GetReportSrdDataFromFile(string name)
        {
            string content = GetReportContent(name);
            return GetReportSrdDataFromContent(content);
        }
        /// <summary>
        /// Načte a vrátí obsah souboru daného jména z adresáře Reports (adresář hledá kdekoliv na cestě od aplikace nahoru)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static string GetReportContent(string name)
        {
            string fullName = ReportDocument.FindReportFile(name);
            if (fullName == null) return null;
            return System.IO.File.ReadAllText(fullName, Encoding.Default);
        }
        #endregion
        #region Tvorba Settingu pro parsování formátu SRD
        /// <summary>
        /// Vytvoří a vrátí ParserSetting, který popisuje formát SRD.
        /// S tímto settingem může následně obecný parser (class: Noris.Schedule.Support.Parser.Parser) rozdělit text souboru SRD na jednotlivé významové segmenty.
        /// </summary>
        /// <returns></returns>
        internal static ParserSetting CreateParserSettingSrd()
        {
            ParserSetting setting = new ParserSetting("Pb7FormatSrd", SETTING_SEGM_TEXT);

            ParserSegmentSetting segment;

            // Text
            segment = new ParserSegmentSetting(SETTING_SEGM_TEXT);
            segment.Blanks = new string[] { " ", "\t" };                // Oddělují jednotlivá slova v rámci stejného segmentu, například:  KOČKA PES BOUDA   jsou tři prvky (ParserSegment) oddělená oddělovačem (Blank)
            segment.Delimiters = new string[] { ",", "+", "-", "*", "/", "<", "=", ">", "<=", ">=", "<>", "%" };
            segment.EndWith = new string[] { "\r\n", "\r", "\n" };      // Ukončí segment a začne nový. Takto zadaná množina řeší i různé styly zadání konce řádku.
            segment.SpecialTexts = new ParserSegmentSpecialTexts[] { new ParserSegmentSpecialTexts("~\"", "\"") };              // Řetězec   ~"  chápeme jako znak  "   a nikoli jako začátek stringu
            segment.InnerSegmentsNames = new string[] { SETTING_SEGM_PAR, SETTING_SEGM_STRING };
            setting.SegmentSettingAdd(segment);

            // Závorka
            segment = new ParserSegmentSetting(SETTING_SEGM_PAR, segment);
            segment.Blanks = new string[] { " ", "\t", "\r\n", "\r", "\n" };    // Oddělují jednotlivá slova v rámci stejného segmentu, například:  KOČKA PES BOUDA   jsou tři prvky (ParserSegment) oddělená oddělovačem (Blank)
            segment.BeginWith = "(";
            segment.EndWith = new string[] { ")" };
            segment.InnerSegmentsNames = new string[] { SETTING_SEGM_TEXT, SETTING_SEGM_PAR, SETTING_SEGM_STRING };
            setting.SegmentSettingAdd(segment);

            // String
            segment = new ParserSegmentSetting(SETTING_SEGM_STRING);
            segment.BeginWith = "\"";
            segment.EndWith = new string[] { "\"" };
            segment.Blanks = new string[] { "~t" };                     // Oddělují jednotlivé texty ve stringu (typicky:  format="[general]~tif(  alt_used_here > 0 , ~"ANO~", ~"! NE !~" )"    )
            segment.SpecialTexts = new ParserSegmentSpecialTexts[] { new ParserSegmentSpecialTexts("~\"", "\"") };              // Řetězec   ~"  chápeme jako znak  "   a nikoli jako konec stringu
            setting.SegmentSettingAdd(segment);

            return setting;
        }
        private const string SETTING_SEGM_TEXT = "SegmText";
        private const string SETTING_SEGM_PAR = "SegmPar";
        private const string SETTING_SEGM_STRING = "SegmString";
        #endregion
        #region Naplnění dokumentu ReportDocument daty ze sestavy SRD
        /// <summary>
        /// Převezme data reportu (SRD) a vloží je do report dokumentu
        /// </summary>
        /// <param name="srdSegments">Parsované segmenty PB7 reportu (SRD formát)</param>
        /// <param name="document">Report Dokument, do něhož se data vkládají</param>
        /// <param name="fileName">Soubor, z něhož se data načítají</param>
        public static void ConvertSrdToDocument(List<Noris.Schedule.Support.Parser.ParserSegment> srdSegments, ReportDocument document, string fileName)
        {
            string currentContent = document.DocumentGetXmlContent();
            try
            {
                document.ClearAll(DocumentNewPresetMode.OnlyRootBand);
                using (Pb7Loader loader = new Pb7Loader(document))
                {
                    loader.ConvertSrdSegments(srdSegments);
                }
                document.DocumentFile = System.IO.Path.ChangeExtension(fileName, "xml");
            }
            catch (Exception)
            {
                document.DocumentSetXmlContent(currentContent);
                throw;
            }
        }
        #region Privátní instance
        /// <summary>
        /// Konstruktor je privátní
        /// </summary>
        private Pb7Loader(ReportDocument document)
        {
            this.Document = document;
            this.BandSrdList = new List<BandSrd>();
            this.BandNameIds = null;
            this.Release = SrdRelease.None;
            this.Units = Pb7Units.Native;
        }
        void IDisposable.Dispose()
        {
            this.Document = null;
            this.BandNameIds = null;
        }
        /// <summary>
        /// Dokument, který se plní
        /// </summary>
        private ReportDocument Document;
        /// <summary>
        /// Verze PowerBuilderu, v níž byl report uložen
        /// </summary>
        private SrdRelease Release;
        /// <summary>
        /// Jednotky měr v sestavě.
        /// Setování provede aktualizaci UnitCoefficient.
        /// </summary>
        private Pb7Units Units
        {
            get { return this._Units; }
            set
            {
                this._Units = value;
                this.UnitCoefficient = ((float)((int)Pb7Units.Centimeter)) / ((float)((int)value));
            }
        }
        private Pb7Units _Units;
        /// <summary>
        /// Přepočtový koeficient z jednotek SRD na milimetry:
        /// počet [milimetry] = počet z SRD * UnitCoefficient / 100f
        /// </summary>
        private float UnitCoefficient;
        private enum SrdRelease { None, Release4, Release7 }
        /// <summary>
        /// Jednotky měr v sestavě SRD
        /// </summary>
        private enum Pb7Units : int
        {
            // Zde uváděné hodnoty enumu jsou hodnotami, které PB7 ukládá jako hodnoty pro shodný rozměr při použití různých jednotek:
            /// <summary>
            /// Nativní builder, 100 mm = 1516
            /// </summary>
            Native = 4480,
            /// <summary>
            /// Pixely, 100 mm = 379
            /// </summary>
            Pixel = 980,
            /// <summary>
            /// Inches, 100 mm = 3947
            /// </summary>
            Inch = 10208,
            /// <summary>
            /// Centimetry, 100 mm = 10027
            /// </summary>
            Centimeter = 25929
        }
        #endregion
        #region Základní metody importu (začátek, kontroly, iterace jednotlivých položek)
        /// <summary>
        /// Fyzická konverze SRD segmentů do ReportDocumentu.
        /// Segmenty jsou vytvářeny po řádcích dokumentu.
        /// Jejich obsah je dělen 
        /// </summary>
        /// <param name="srdSegments"></param>
        private void ConvertSrdSegments(List<ParserSegment> srdSegments)
        {
            int count = srdSegments.Count;
            this.ConvertSrdCheckRowCount(count);
            this.ConvertSrdCheckHeader(srdSegments[0]);
            int begin = this.ConvertSrdCheckRelease(srdSegments);
            for (int s = begin + 1; s < count; s++)
                this.ConvertSrdSegment(srdSegments[s]);
            this.CheckBandSrdProcessed();
        }
        /// <summary>
        /// Kontrola počtu řádků
        /// </summary>
        /// <param name="count"></param>
        private void ConvertSrdCheckRowCount(int count)
        {
            if (count > 5) return;
            throw new DataException("Format of SRD file is invalid: row count is too small (" + count.ToString() + ").");
        }
        /// <summary>
        /// Kontrola řádku 0 (záhlaví)
        /// </summary>
        /// <param name="segment"></param>
        private void ConvertSrdCheckHeader(ParserSegment segment)
        {
            string text = segment.Text;
            if (text.StartsWith(SRD_HEADER)) return;
            throw new DataException("Format of SRD file is invalid: Line 1 does not match expected content. Line=" + text + "; expected=" + SRD_HEADER + ".");
        }
        /// <summary>
        /// Kontrola řádku 1 (release)
        /// </summary>
        /// <param name="segments"></param>
        private int ConvertSrdCheckRelease(List<ParserSegment> segments)
        {
            this.Release = SrdRelease.None;
            for (int s = 1; s < segments.Count; s++)
            {
                ParserSegment segment = segments[s];
                string text = segment.Text;
                if (text.StartsWith(SRD_RELEASE1))
                    this.Release = SrdRelease.Release4;
                else if (text.StartsWith(SRD_RELEASE2))
                    this.Release = SrdRelease.Release4;
                else if (text.StartsWith(SRD_RELEASE3))
                    this.Release = SrdRelease.Release4;
                else if (text.StartsWith(SRD_RELEASE4))
                    this.Release = SrdRelease.Release4;
                else if (text.StartsWith(SRD_RELEASE5))
                    this.Release = SrdRelease.Release4;
                else if (text.StartsWith(SRD_RELEASE6))
                    this.Release = SrdRelease.Release4;
                else if (text.StartsWith(SRD_RELEASE7))
                    this.Release = SrdRelease.Release7;

                if (this.Release != SrdRelease.None)
                    return s;
            }
            throw new DataException("Format of SRD file is invalid: file does not contain Pb7Release expression. (expected=" + SRD_HEADER + ").");
        }
        #endregion
        #region Detekce jednotlivých položek, plnění specifických dat
        /// <summary>
        /// Zpracování dalších segmentů - detekce názvu a rozdělení do odpovídající metody
        /// </summary>
        /// <param name="segment"></param>
        private void ConvertSrdSegment(ParserSegment segment)
        {
            if (segment.ValueList.Count != 2) return;
            string name = segment.ValueList[0].Text;
            KeyValueSegmentList values = ConvertSrdSplitValues(segment.ValueList[1]);
            switch (name)
            {
                case SRD_DATAWINDOW:
                    this.ConvertSrdSegmentDataWindow(name, values);
                    break;
                case SRD_BAND_HEADER:
                case SRD_BAND_DETAIL:
                case SRD_BAND_SUMMARY:
                case SRD_BAND_FOOTER:
                    this.ConvertSrdSegmentBand(name, values);
                    break;
                case SRD_DATA_TABLE:
                    this.ConvertSrdSegmentTable(name, values);
                    break;
                case SRD_GROUP:
                    this.ConvertSrdSegmentGroup(name, values);
                    break;
                case SRD_OBJECT_TEXT:
                    this.CheckBandSrdProcessed();
                    this.ConvertSrdSegmentText(name, values);
                    break;
                case SRD_OBJECT_COLUMN:
                    this.CheckBandSrdProcessed();
                    this.ConvertSrdSegmentColumn(name, values);
                    break;
                case SRD_OBJECT_COMPUTE:
                    this.CheckBandSrdProcessed();
                    this.ConvertSrdSegmentCompute(name, values);
                    break;
                case SRD_OBJECT_LINE:
                    break;
                case SRD_OBJECT_RECTANGLE:
                    this.CheckBandSrdProcessed();
                    this.ConvertSrdSegmentRectangle(name, values);
                    break;
                case SRD_OBJECT_HTMLTABLE:
                case SRD_OBJECT_HTMLGEN:
                    break;
            }
        }
        /// <summary>
        /// Načte data ze segmentu "datawindow"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentDataWindow(string name, KeyValueSegmentList values)
        {   // datawindow(units=0 timer_interval=0 color=16777215 processing=0 HTMLDW=no print.documentname="" 
            //            print.orientation = 1 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 
            //            print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no )
            this.Units = GetUnits(values, "units");
            this.Document.ReportProperties.BackColor = this.GetColor(values, "color");
            this.Document.ReportProperties.DocumentName = values.FindValue<string>("print.documentname", "");
            this.Document.ReportProperties.PageSize = PageSizeInfo.GetPageSize(values.FindValue<int>("print.paper.size", 0), 0);
            this.Document.ReportProperties.PageOrientation = this.GetPageOrientation(values, "print.orientation");
            this.Document.ReportProperties.PrintMargin = this.GetPadding(values, "print.margin");
        }
        /// <summary>
        /// Načte data ze segmentu "table"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentTable(string name, KeyValueSegmentList values)
        {   // segment "table" obsahuje páry hodnot: column=(...) [opakovaně], a klíče: retrieve a arguments:
            ReportData reportData = this.Document.RootBand.ReportData;
            reportData.Clear();
            reportData.DataQueryEditEnabled = true;
            foreach (KeyValueSegment pair in values)
            {
                string key = pair.Key;
                switch (key)
                {
                    case SRD_TABLE_COLUMN:
                        this.ConvertSrdSegmentTableColumn(pair, reportData);
                        break;
                    case SRD_TABLE_RETRIEVE:
                        this.ConvertSrdSegmentTableRetrieve(pair, reportData);
                        break;
                    case SRD_TABLE_ARGUMENTS:
                        this.ConvertSrdSegmentTableArguments(pair, reportData);
                        break;
                }
            }
        }
        /// <summary>
        /// Zpracuje data jednoho columnu: načte je ze segmentu, a vloží do this.Document.RootBand.ReportData
        /// </summary>
        /// <param name="pair">Key+Value, kde Value obsahuje informace o sloupci</param>
        /// <param name="reportData">Data reportu</param>
        private void ConvertSrdSegmentTableColumn(KeyValueSegment pair, ReportData reportData)
        {   // column=(type=char(40) updatewhereclause=yes name=dil_nazev_subjektu dbname="dil_nazev_subjektu" )
            ParserSegmentValue segmentValue = pair.SegmentValues[0];          // (type=char(40) ... )
            if (!segmentValue.HasInnerSegment) return;
            KeyValueSegmentList values = ConvertSrdSplitValues(segmentValue); // Seznam párů: klíč=hodnota
            string type = values.FindValue<string>("type", "");
            string update = values.FindValue<string>("updatewhereclause", "");
            string name = values.FindValue<string>("name", "");               // Název používaný v reportu (v jednotlivých fields)
            string dbname = values.FindValue<string>("dbname", "");           // Název, pod nímž se data načtou z SQL serveru dotazem v Retrieve

            // Data uložit do columnů:
            reportData.Columns.Add(dbname, name, type);
        }
        /// <summary>
        /// Zpracuje příkaz Retrieve a vloží jej do this.Document.RootBand.ReportData
        /// </summary>
        /// <param name="pair">Key+Value, kde Value obsahuje informace o Retrieve</param>
        /// <param name="reportData">Data reportu</param>
        private void ConvertSrdSegmentTableRetrieve(KeyValueSegment pair, ReportData reportData)
        {
            this.Document.RootBand.ReportData.DataQuery = pair.Value;
            this.Document.RootBand.ReportData.RootClassNumber = 1180;
        }
        /// <summary>
        /// Zpracuje příkaz Arguments a vloží jej do this.Document.RootBand.ReportData
        /// </summary>
        /// <param name="pair">Key+Value, kde Value obsahuje informace o parametrech</param>
        /// <param name="reportData">Data reportu</param>
        private void ConvertSrdSegmentTableArguments(KeyValueSegment pair, ReportData reportData)
        {
            ParserSegment segment = null;
            ParserSegmentValue value = pair.SegmentValues.FirstOrDefault(v => v.HasInnerSegment && v.InnerSegment.SegmentName == SETTING_SEGM_PAR);
            while (value.HasInnerSegment)
            {
                segment = value.InnerSegment;
                if (segment.SegmentName == SETTING_SEGM_PAR && segment.ValueList.Count != 1) break;
                value = segment.ValueList.FirstOrDefault(v => v.HasInnerSegment && v.InnerSegment.SegmentName == SETTING_SEGM_PAR);
            }

            if (segment != null && segment.SegmentName == SETTING_SEGM_PAR && segment.ValueList.Count > 1)
            {
                KeyValueSegmentList values = ConvertSrdSplitArguments(segment.ParentValue); // Seznam párů: { "name", type [, "name2", type2...] }
                this.Document.RootBand.ReportData.Parameters.Import(values.ToParameterCollection());
            }
        }
        /// <summary>
        /// Načte data ze segmentů "header", "summary", "footer", "detail"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentBand(string name, KeyValueSegmentList values)
        {   // header(height=360 color="536870912" )
            BandType type = GetBandType(name);
            float height = GetDimension(values, "height");
            Color color = GetColor(values, "color");
            this.AddBandSrd(type, name, height, color, 0, null);
        }
        /// <summary>
        /// Načte data ze segmentu "group"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentGroup(string name, KeyValueSegmentList values)
        {   // group(level=1 header.height=80 trailer.height=12 by=("dil_cislo_subjektu" ) header.color="536870912" trailer.color="536870912" )
            string groupBy = values.FindValue<string>("by", "");
            int groupLevel = values.FindValue<int>("level", 0);

            float height = 0;
            Color color = GetColor(values, "header.color");
            this.AddBandSrd(BandType.GroupBase, "group" + groupLevel.ToString(), height, color, groupLevel - 1, groupBy);  // GroupLevel - 1 !!!
            
            height = GetDimension(values, "header.height");
            color = GetColor(values, "header.color");
            this.AddBandSrd(BandType.Header, "header", height, color, groupLevel, groupBy);

            height = GetDimension(values, "trailer.height");
            color = GetColor(values, "trailer.color");
            this.AddBandSrd(BandType.Footer, "trailer", height, color, groupLevel, groupBy);
        }
        /// <summary>
        /// Načte data ze segmentu "text"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentText(string name, KeyValueSegmentList values)
        {   // text(band=header alignment="2" text="Alternativní komponenty TPV" border="0" color="0" x="1129" y="36" height="92" width="2048"  
            //      name=t_4  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" 
            //      background.mode="1" background.color="553648127" )
            int ownerBandId = this.GetOwnerBandId(values);
            ReportBand ownerBand = this.Document.GetBand(ownerBandId);
            string text = values.FindValue<string>("text", "");
            RectangleF area = this.GetRectangle(values, "");
            ContentAlignment alignment = this.GetAlignment(values, "alignment");
            Font font = this.GetFont(values, "");

            this.Document.AddComponent(new ReportComponent(this.Document, 
                new ReportObjects.ReportObjectLabel()
                {
                    Alignment = alignment, 
                    Text = text,
                    Font = font 
                })
                {
                    OwnerTopBandId = ownerBandId,
                    RelativeBounds = RelativeRectangleF.CreateRelative(area, ownerBand.LogicalSize) 
                });
        }
        /// <summary>
        /// Načte data ze segmentu "column"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentColumn(string name, KeyValueSegmentList values)
        {   // column(band=header.1 id=3 alignment="0" tabsequence=32766 border="0" color="0" x="526" y="4" height="76" width="1870" 
            //        format="[general]"  name=dil_nazev_subjektu edit.limit=40 edit.case=any edit.autoselect=yes edit.autohscroll=yes  
            //        font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" 
            //        background.mode="1" background.color="536870912" )

            // column(band=detail id=6 alignment="0" tabsequence=32766 border="0" color="0" x="46" y="100" height="117" width="1573" 
            //        format="[general]"  name=hotline_polozka_problem  resizeable=1  moveable=1 height.autosize=yes edit.limit=4099 
            //        edit.case=any edit.focusrectangle=no edit.autoselect=yes  
            //        font.face="Times New Roman CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="2" font.charset="-18"
            //        background.mode="1" background.color="536870912" )
            int ownerBandId = this.GetOwnerBandId(values);
            ReportBand ownerBand = this.Document.GetBand(ownerBandId);
            string sourceData = this.Document.RootBand.HeaderText;
            string sourceColumn = values.FindValue<string>("name", "");
            string format = values.FindValue<string>("format", "");
            RectangleF area = this.GetRectangle(values, "");
            ContentAlignment alignment = this.GetAlignment(values, "alignment");
            Font font = this.GetFont(values, "");
            Color backColor = this.GetColor(values, "background.color");
            bool autosizeHeight = this.GetBoolean(values, "height.autosize");

            this.Document.AddComponent(new ReportComponent(this.Document,
                new ReportObjects.ReportObjectField()
                {
                    Alignment = alignment,
                    DataSource = sourceData,
                    SourceColumn = sourceColumn,
                    Format = format,
                    AutosizeHeight = autosizeHeight,
                    Font = font,
                    BackColor = backColor
                })
            {
                OwnerTopBandId = ownerBandId,
                RelativeBounds = RelativeRectangleF.CreateRelative(area, ownerBand.LogicalSize)
            });
        }
        /// <summary>
        /// Načte data ze segmentu "compute"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentCompute(string name, KeyValueSegmentList values)
        {   // compute(band=trailer.1 alignment="0" expression="year( today() )"border="0" color="0" x="590" y="324" height="92" width="297"
            //         format="[GENERAL]"  name=compute_1  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" 
            //         background.mode="1" background.color="536870912" )
            // compute(band=trailer.1 alignment="1" expression="sum (   dotnet_hod for group 1 )"border="0" 
            //         color="0" x="2761" y="16" height="64" width="357" format="##,###,###,##0.00"  name=compute_4  
            //         font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" 
            //         background.mode="1" background.color="536870912" )

            int ownerBandId = this.GetOwnerBandId(values);
            ReportBand ownerBand = this.Document.GetBand(ownerBandId);
            string sourceData = this.Document.RootBand.HeaderText;
            string sourceColumn = values.FindValue<string>("expression", "");
            string format = values.FindValue<string>("format", "");
            RectangleF area = this.GetRectangle(values, "");
            ContentAlignment alignment = this.GetAlignment(values, "alignment");
            Font font = this.GetFont(values, "");
            Color backColor = this.GetColor(values, "background.color");

            this.Document.AddComponent(new ReportComponent(this.Document,
                new ReportObjects.ReportObjectField()
                {
                    Alignment = alignment,
                    DataSource = sourceData,
                    SourceColumn = sourceColumn,
                    Format = format,
                    Font = font,
                    BackColor = backColor
                })
            {
                OwnerTopBandId = ownerBandId,
                RelativeBounds = RelativeRectangleF.CreateRelative(area, ownerBand.LogicalSize)
            });
        }
        /// <summary>
        /// Načte data ze segmentu "rectangle"
        /// </summary>
        /// <param name="name"></param>
        /// <param name="values"></param>
        private void ConvertSrdSegmentRectangle(string name, KeyValueSegmentList values)
        {   // rectangle(band=detail x="4256" y="0" height="80" width="219"  name=ramec1 visible="1~tif( alt_used_here = 0, 1, 0)"
            //           slideup=allabove brush.hatch="7" brush.color="553582847" pen.style="0" pen.width="9" pen.color="0"  
            //           background.mode="2" background.color="16777215" )
            int ownerBandId = this.GetOwnerBandId(values);
            ReportBand ownerBand = this.Document.GetBand(ownerBandId);
            RectangleF area = this.GetRectangle(values, "");
            Color backColor = this.GetColor(values, "background.color");
            Color borderColor = this.GetColor(values, "pen.color");
            float borderWidth = this.GetDimension(values, "pen.width");

            this.Document.AddComponent(new ReportComponent(this.Document,
                new ReportObjects.ReportObjectShape()
                {
                    Shape = ReportObjects.ShapeType.Rectangle,
                    BackColor = backColor,
                    BorderColor = borderColor,
                    BorderWidth = borderWidth
                })
            {
                OwnerTopBandId = ownerBandId,
                RelativeBounds = RelativeRectangleF.CreateRelative(area, ownerBand.LogicalSize)
            });

        }
        #endregion
        #region Konvertory (jednotky, míry, barvy)
        /// <summary>
        /// Vrátí typ Bandu podle jeho názvu. Pouze pro Bandy základní úrovně, ne grupy.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private BandType GetBandType(string name)
        {
            switch (name)
            {
                case SRD_BAND_HEADER: return BandType.Header;
                case SRD_BAND_DETAIL: return BandType.Detail;
                case SRD_BAND_FOOTER: return BandType.Footer;
                case SRD_BAND_SUMMARY: return BandType.Summary;
            }
            return BandType.None;
        }
        /// <summary>
        /// Vrátí jednotku měr
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Pb7Units GetUnits(KeyValueSegmentList values, string name)
        {
            int units = values.FindValue<int>("units", 0);
            switch (units)
            {
                case 0: return Pb7Units.Native;
                case 1: return Pb7Units.Pixel;
                case 2: return Pb7Units.Inch;
                case 3: return Pb7Units.Centimeter;
            }
            return Pb7Units.Native;
        }
        /// <summary>
        /// Vrátí zarovnání prvku
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private ContentAlignment GetAlignment(KeyValueSegmentList values, string name)
        {
            int alignment = values.FindValue<int>(name, 0);
            switch (alignment)
            {
                case 0: return ContentAlignment.TopLeft;
                case 1: return ContentAlignment.TopRight;
                case 2: return ContentAlignment.TopCenter;
                case 3: return ContentAlignment.TopLeft;    // Justify
            }
            return ContentAlignment.TopLeft;
        }
        /// <summary>
        /// Vrátí rozměr převedený na milimetry
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private float GetDimension(KeyValueSegmentList values, string name)
        {
            int dimension = values.FindValue<int>(name, 0);
            return (float)dimension * this.UnitCoefficient / 100f ;
        }
        /// <summary>
        /// Vrátí rectangle, který je specifikován hodnotami x, y, height, width (s daným prefixem).
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private RectangleF GetRectangle(KeyValueSegmentList values, string name)
        {
            string prefix = (String.IsNullOrEmpty(name) ? "" : name + ".");
            float x = this.GetDimension(values, prefix + "x");
            float y = this.GetDimension(values, prefix + "y");
            float width = this.GetDimension(values, prefix + "width");
            float height = this.GetDimension(values, prefix + "height");
            return new RectangleF(x, y, width, height);
        }
        /// <summary>
        /// Načte a vrátí okraje
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private PaddingF GetPadding(KeyValueSegmentList values, string name)
        {   // print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96
            string prefix = (String.IsNullOrEmpty(name) ? "" : name + ".");
            float top = this.GetDimension(values, prefix + "top");
            float left = this.GetDimension(values, prefix + "left");
            float right = this.GetDimension(values, prefix + "right");
            float bottom = this.GetDimension(values, prefix + "bottom");
            return new PaddingF(top, left, right, bottom);
        }
        /// <summary>
        /// Vrátí boolean
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private bool GetBoolean(KeyValueSegmentList values, string name)
        {
            string value = values.FindValue<string>(name, "");
            return (value == "yes");
        }
        /// <summary>
        /// Vrátí barvu
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Color GetColor(KeyValueSegmentList values, string name)
        {
            Int32 color = values.FindValue<Int32>(name, 0);
            string c = color.ToString("X8");
            if (c == "20000000") return Color.White;

            int a = ((color >> 16) & 0x0000ff00) >> 8;
            if (a > 0) return Color.White;

            int r = color & 0x000000ff;
            int g = (color & 0x0000ff00) >> 8;
            int b = (color & 0x00ff0000) >> 16;
            Color result = Color.FromArgb(r, g, b);
            return result;
        }
        /// <summary>
        /// Vrátí font
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Font GetFont(KeyValueSegmentList values, string name)
        {   // font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238"
            string prefix = (String.IsNullOrEmpty(name) ? "" : name + ".");
            string fontName = values.FindValue<string>(prefix + "font.face", "");
            int fontSize = -values.FindValue<int>(prefix + "font.height", 0);
            int fontWeight = values.FindValue<int>(prefix + "font.weight", 0);
            int fontFamily = values.FindValue<int>(prefix + "font.family", 0);
            int fontPitch = values.FindValue<int>(prefix + "font.pitch", 0);
            int fontCharset = values.FindValue<int>(prefix + "font.charset", 0);
            FontStyle fontStyle = (fontWeight >= 600 ? FontStyle.Bold : FontStyle.Regular);
            Font font = null;
            try
            {
                font = new Font(fontName, fontSize, fontStyle);
            }
            catch (Exception)
            {
                font = (Font)this.Document.DefaultFont.Clone();
            }
            return font;
        }
        /// <summary>
        /// Vrátí orientaci stránky
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private PageOrientationType GetPageOrientation(KeyValueSegmentList values, string name)
        {
            int orientation = values.FindValue<int>(name, 0);
            if (orientation == 0 || orientation == 1 || orientation == 2)
                return (PageOrientationType)orientation;
            return PageOrientationType.Default;
        }
        /// <summary>
        /// Vrátí ID bandu, do něhož spadá komponenta podle načtených hodnot
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        private int GetOwnerBandId(KeyValueSegmentList values)
        {
            string band = values.FindValue<string>("band", "");
            int ownerBandId = this.BandNameIds[band];
            return ownerBandId;
        }
        #endregion
        #region Mezipaměť na data pro ReportBand, sestavení logického modelu z dat SRD, odpovídající třída BandSrd
        /// <summary>
        /// Přidá data pro Band do mezipaměti.
        /// Pokud mezipaměť již byla zpracována, ohlásí chybu.
        /// </summary>
        /// <param name="bandType"></param>
        /// <param name="name"></param>
        /// <param name="height"></param>
        /// <param name="color"></param>
        /// <param name="groupLevel"></param>
        /// <param name="groupExpression"></param>
        private void AddBandSrd(BandType bandType, string name, float height, Color color, int groupLevel, string groupExpression)
        {
            if (this.BandSrdList == null)
                throw new DataException("Unable to add additional headers after being processed.");
            BandSrd band = new BandSrd() { BandType = bandType, Name = name, Height = height, Color = color, GroupLevel = groupLevel, GroupExpression = groupExpression };
            this.BandSrdList.Add(band);
        }
        /// <summary>
        /// Metoda prověří, zda jsou nastřádané prvky v this.BandSrdList, a pokud ano, pak z nich vytvoří sadu Bands do dokumentu.
        /// Po zpracování vloží do this.BandSrdList hodnotu null.
        /// Pokud už byly prvky zpracovány a v this.BandSrdList je null, tak nedělá nic.
        /// Metodu je vhodné volat před přidáním každé komponenty.
        /// </summary>
        private void CheckBandSrdProcessed()
        {
            if (this.BandSrdList == null) return;

            this.BandNameIds = new Dictionary<string, int>();

            // Musíme udělat jednu úpravu: band typu Detail (existuje jen jeden, a je psán do levelu 0)
            // je třeba dát do nejvyšší grupy, aby se zobrazoval v ní:
            int maxGroup = this.BandSrdList.Max(b => b.GroupLevel);
            foreach (BandSrd b in this.BandSrdList.Where(b => b.BandType == BandType.Detail))
                b.GroupLevel = maxGroup;
            // Nyní setřídíme Bands podle GroupLevel a BandType:
            this.BandSrdList.Sort(BandSrd.CompareByOrder);

            Dictionary<int, int> ownerIds = new Dictionary<int, int>();
            ownerIds.Add(0, this.Document.RootBand.BandId);
            foreach (BandSrd bandSrd in this.BandSrdList)
            {
                // Owner tohoto bandu:
                int ownerBandId = ownerIds[0];
                if (bandSrd.GroupLevel > 0) // && bandSrd.BandType != BandType.GroupBase)
                    ownerBandId = ownerIds[bandSrd.GroupLevel];

                // Band do dokumentu:
                ReportBand band = new ReportBand(this.Document, bandSrd.RepBandType);
                band.OwnerBandId = ownerBandId;
                band.HeaderText = bandSrd.Name;
                band.LogicalHeight = bandSrd.Height;
                band.HeaderBackColor = bandSrd.Color;
                this.Document.AddBand(band);

                if (bandSrd.BandType == BandType.GroupBase)
                    ownerIds.Add(bandSrd.GroupLevel + 1, band.BandId);

                // Název a ID do místního indexu:
                this.BandNameIds.Add(bandSrd.BandSrdName, band.BandId);
            }

            this.BandSrdList = null;
        }
        /// <summary>
        /// Mezipaměť dat Bands, plní se z prvků typu header, detail, ..., group.
        /// Zpracovává se před první komponentou, pomocí metody this.CheckBandSrdProcessed().
        /// </summary>
        private List<BandSrd> BandSrdList;
        /// <summary>
        /// Výsledná paměť (index), která podle klíče bandu určí jeho ID.
        /// Vytváří se při zpracování BandSrdList v metodě this.CheckBandSrdProcessed().
        /// </summary>
        private Dictionary<string, int> BandNameIds;
        /// <summary>
        /// Třída pro uchování dat o bandech v mezipaměti
        /// </summary>
        private class BandSrd
        {
            public BandType BandType;
            public string Name;
            public float Height;
            public Color Color;
            public int GroupLevel;
            /// <summary>
            /// Typ Bandu v rámci Reportu
            /// </summary>
            public ReportBandType RepBandType
            {
                get
                {
                    switch (this.BandType)
                    {
                        case Pb7Loader.BandType.Header: return ((this.GroupLevel > 0) ? ReportBandType.GroupHeader : ReportBandType.PageHeader);
                        case Pb7Loader.BandType.Title: return ReportBandType.Title;
                        case Pb7Loader.BandType.GroupBase: return ReportBandType.Group;
                        case Pb7Loader.BandType.Detail: return ReportBandType.Detail;
                        case Pb7Loader.BandType.Summary: return ReportBandType.Summary;
                        case Pb7Loader.BandType.Footer: return ((this.GroupLevel > 0) ? ReportBandType.GroupFooter : ReportBandType.PageFooter);
                    }
                    return ReportBandType.None;
                }
            }
            public string GroupExpression;
            public string BandSrdName
            {
                get
                {
                    if (this.BandType == Pb7Loader.BandType.GroupBase)
                        return "group." + (this.GroupLevel + 1).ToString();
                    if (this.GroupLevel == 0 || this.BandType == Pb7Loader.BandType.Detail)
                        return this.Name;
                    switch (this.BandType)
                    {
                        case Pb7Loader.BandType.Header:
                            return "header." + this.GroupLevel.ToString();
                        case Pb7Loader.BandType.Footer:
                            return "trailer." + this.GroupLevel.ToString();
                    }
                    return this.Name + "." + this.GroupLevel.ToString();
                }
            }
            /// <summary>
            /// Vizualizace
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                return this.Name + (this.GroupLevel == 0 ? "" : " Group " + this.GroupLevel.ToString() + "; by: " + this.GroupExpression);
            }
            /// <summary>
            /// Komparátor pro List.Sort()
            /// Na první místa dává položky podle čísla GroupLevel.
            /// v rámci shodné grupy pak podle pořadí BandType.
            /// </summary>
            /// <param name="a"></param>
            /// <param name="b"></param>
            /// <returns></returns>
            public static int CompareByOrder(BandSrd a, BandSrd b)
            {
                int cmp;
                cmp = a.GroupLevel.CompareTo(b.GroupLevel);
                if (cmp != 0) return cmp;
                cmp = ((int)a.BandType).CompareTo((int)b.BandType);
                return cmp;
            }
        }
        private enum BandType : int
        {
            None = 0,
            Header,
            Title,
            /// <summary>
            /// Základna grupy. Tato základna má GroupLevel o 1 nižší než ostatní Bands grupy (Header a Trailer),
            /// to proto, aby se základna zatřídila mezi položky vyšší úrovně jako jedna z nich (typicky místo detailu).
            /// </summary>
            GroupBase,
            Detail,
            Summary,
            Footer
        }
        #endregion
        #region Vytvoření seznamu KeyValueSegment list, odpovídající třída KeyValueSegmentList
        /// <summary>
        /// Vytvoří seznam Key-Value z dat dodaného segmentu.
        /// Segment očekáváme v tvaru: { key1 = value1 key2 = value2 key3 = value3 } atd.
        /// Key musí být Text, musí být pouze jeden před znakem rovnítko.
        /// Value může být libovolná sekvence Value, delimitery, InnerSegment. Přebírá se od rovnítka do příštího Key.
        /// Příklad komplikovanějšího segmentu: { key1 = func1(25+3) * func2 (bbb) key2 = func3() + "text" key3 = 0 }
        /// </summary>
        /// <param name="segmentValue"></param>
        /// <returns></returns>
        private static KeyValueSegmentList ConvertSrdSplitValues(ParserSegmentValue segmentValue)
        {
            KeyValueSegmentList result = new KeyValueSegmentList();
            if (segmentValue.HasInnerSegment)
            {
                List<ParserSegmentValue> values = segmentValue.InnerSegment.ValueList;
                // Segment obsahuje formulaci: { key1 = value1 key2 = value2 key3 = value3 } atd.
                // Přičemž jako "value" nemusí být jeden objekt ParserSegmentValue, ale může jich být více: 
                //   typicky "max(columns)" jsou dvě Values za sebou: "max" a "(columns)", přičemž "(columns)" je segment.
                // Zpracuji tedy segment následovně: 
                //   - nejprve najdu indexy prvků, které jsou "="
                //   - pak ke každému "=" najdu index prvku před ním = key
                //   - pak všechno od "=" k příštímu "key" je "value", s tím že do Value beru i vnitřní delimitery (ale ne vnější).
                for (int q = 0; q < values.Count; q++)
                {
                    ParserSegmentValue value = values[q];
                    if (value.ValueType == ParserSegmentValueType.Delimiter && value.Text == "=")
                    {   // Našli jsme rovnítko:
                        for (int k = q - 1; k >= 0; k--)
                        {   // Dohledáme klíč vlevo před rovnítkem:
                            ParserSegmentValue key = values[k];
                            if (key.ValueType == ParserSegmentValueType.Text)
                            {
                                KeyValueSegment pair = new KeyValueSegment(k, key.Text, q);
                                result.Add(pair);
                                break;
                            }
                        }
                    }
                }

                // Nyní pro každý ParserSegmentValue najdu všechny Values za jeho rovnítkem před příštím Key (anebo do konce), a to bude Value daného páru:
                for (int p = 0; p < result.Count; p++)
                {
                    KeyValueSegment pair = result[p];
                    int firstValueIndex = pair.EqualIndex + 1;
                    int nextKeyIndex = (p < (result.Count - 1) ? result[p + 1].KeyIndex : values.Count);     // Hodnota indexu, kterou již do "value" brát nebudu
                    pair.AddValues(values.GetRange(firstValueIndex, nextKeyIndex - firstValueIndex));        // Řada hodnot, které patří do Values daného pair
                }
            }
            return result;
        }
        /// <summary>
        /// Vytvoří seznam Key-Value z dat dodaného segmentu.
        /// Segment očekáváme v tvaru: { "name", type [, "name2", type2...] }.
        /// Key je segment v uvozovkách, Value je text za čárkou.
        /// </summary>
        /// <param name="segmentValue"></param>
        /// <returns></returns>
        private static KeyValueSegmentList ConvertSrdSplitArguments(ParserSegmentValue segmentValue)
        {
            KeyValueSegmentList result = new KeyValueSegmentList();
            if (segmentValue.HasInnerSegment)
            {
                int keyIndex = -1;
                int equalIndex = -1;
                string key = null;
                KeyValueSegment pair = null;
                List<ParserSegmentValue> values = segmentValue.InnerSegment.ValueList;
                for (int v = 0; v < values.Count; v++)
                {
                    ParserSegmentValue value = values[v];
                    if (value.ValueType == ParserSegmentValueType.InnerSegment && value.InnerSegment.SegmentName == SETTING_SEGM_STRING && key == null && pair == null)
                    {   // "key":
                        keyIndex = v;
                        key = value.InnerSegment.InnerText;
                    }
                    else if (value.ValueType == ParserSegmentValueType.Delimiter && value.Text == "," && key != null && pair == null)
                    {
                        equalIndex = v;
                        pair = new KeyValueSegment(keyIndex, key, equalIndex);
                        result.Add(pair);
                        key = null;
                    }
                    else if (pair != null && value.ValueType == ParserSegmentValueType.Text)
                    {
                        pair.AddValue(value);
                        pair = null;
                    }
                }
            }
            return result;
        }
        /// <summary>
        /// Seznam triád Key-Value-Segment
        /// </summary>
        private class KeyValueSegmentList : List<KeyValueSegment>
        {
            /// <summary>
            /// Najde hodnotu podle názvu a vrátí ji v daném typu
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="name"></param>
            /// <param name="defaultValue"></param>
            /// <returns></returns>
            public T FindValue<T>(string name, T defaultValue)
            {
                KeyValueSegment item = this.FirstOrDefault(kvp => kvp.Key == name);
                if (item == null) return defaultValue;

                if (typeof(T).Equals(typeof(String)))
                    return (T)(object)item.Value;
                if (typeof(T).Equals(typeof(Byte)))
                    return (T)Convertor.StringToByte(item.Value);
                if (typeof(T).Equals(typeof(Color)))
                    return (T)Convertor.StringToColor(item.Value);
                if (typeof(T).Equals(typeof(DateTime)))
                    return (T)Convertor.StringToDateTime(item.Value);
                if (typeof(T).Equals(typeof(DateTimeOffset)))
                    return (T)Convertor.StringToDateTimeOffset(item.Value);
                if (typeof(T).Equals(typeof(Decimal)))
                    return (T)Convertor.StringToDecimal(item.Value);
                if (typeof(T).Equals(typeof(Double)))
                    return (T)Convertor.StringToDouble(item.Value);
                if (typeof(T).Equals(typeof(Char)))
                    return (T)Convertor.StringToChar(item.Value);
                if (typeof(T).Equals(typeof(Int16)))
                    return (T)Convertor.StringToInt16(item.Value);
                if (typeof(T).Equals(typeof(Int32)))
                    return (T)Convertor.StringToInt32(item.Value);
                if (typeof(T).Equals(typeof(Int64)))
                    return (T)Convertor.StringToInt64(item.Value);
                if (typeof(T).Equals(typeof(SByte)))
                    return (T)Convertor.StringToSByte(item.Value);
                if (typeof(T).Equals(typeof(Single)))
                    return (T)Convertor.StringToSingle(item.Value);
                if (typeof(T).Equals(typeof(TimeSpan)))
                    return (T)Convertor.StringToTimeSpan(item.Value);
                if (typeof(T).Equals(typeof(UInt16)))
                    return (T)Convertor.StringToUInt16(item.Value);
                if (typeof(T).Equals(typeof(UInt32)))
                    return (T)Convertor.StringToUInt32(item.Value);
                if (typeof(T).Equals(typeof(UInt64)))
                    return (T)Convertor.StringToUInt64(item.Value);

                return defaultValue;
            }
            /// <summary>
            /// Svoje hodnoty konvertuje na seznam parametrů
            /// </summary>
            /// <returns></returns>
            public ReportDataParamCollection ToParameterCollection()
            {
                ReportDataParamCollection collection = new ReportDataParamCollection();
                foreach (KeyValueSegment pair in this)
                    collection.Add(":" + pair.Key, ConvertParamType(pair.Value));
                return collection;
            }
            /// <summary>
            /// Vrátí datový typ parametru (DataType) podle daného názvu typu (powerbuildrovský název typu).
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            private ReportColumnDataType ConvertParamType(string value)
            {
                switch (value.Trim().ToLower())
                {
                    case "numeric": return ReportColumnDataType.Int;
                    case "number": return ReportColumnDataType.Int;
                }
                // Necháme si poradit od odborníků:
                return ReportData.ConvertParamType(value);
            }
        }
        /// <summary>
        /// Triáda Key-Value-Segment.
        /// Nese klíč, textovou hodnotu a současně seznam ParserSegmentValue, které tvoří hodnotu (pro pozdější snadné další parsování vnitřku)
        /// </summary>
        private class KeyValueSegment
        {
            /// <summary>
            /// Konstruktor
            /// </summary>
            /// <param name="keyIndex"></param>
            /// <param name="key"></param>
            /// <param name="equalIndex"></param>
            public KeyValueSegment(int keyIndex, string key, int equalIndex)
            {
                this._KeyIndex = keyIndex;
                this._Key = key;
                this._EqualIndex = equalIndex;
                this._Value = null;
                this._SegmentValues = null;
            }
            private int _KeyIndex;
            private int _EqualIndex;
            private string _Key;
            private string _Value;
            private List<ParserSegmentValue> _SegmentValues;
            /// <summary>
            /// Vizualizace
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                return this.Key + (this._SegmentValues == null ? "" : "=" + this.Value);
            }
            /// <summary>
            /// Pozice value která je Key
            /// </summary>
            public int KeyIndex { get { return this._KeyIndex; } }
            /// <summary>
            /// Pozice delimiteru "="
            /// </summary>
            public int EqualIndex { get { return this._EqualIndex; } }
            /// <summary>
            /// Textový klíč
            /// </summary>
            public string Key { get { return this._Key; } }
            /// <summary>
            /// Textová hodnota
            /// </summary>
            public string Value { get { return this._Value; } }
            /// <summary>
            /// SegmentValue
            /// </summary>
            public List<ParserSegmentValue> SegmentValues { get { return this._SegmentValues; } }
            /// <summary>
            /// Přidá do sebe další Value
            /// </summary>
            /// <param name="values"></param>
            public void AddValue(ParserSegmentValue value)
            {
                if (this._SegmentValues == null)
                    this._SegmentValues = new List<ParserSegmentValue>();
                if (value != null)
                {
                    this._SegmentValues.Add(value);
                    string text = "";
                    foreach (ParserSegmentValue v in this._SegmentValues)
                        text += v.Text;
                    text = text.Trim();

                    // Odstranit uvozovky na začátku a na konci:
                    int length = text.Length;
                    if (length >= 2 && text[0] == '\"' && text[length - 1] == '\"')
                        text = text.Substring(1, length - 2);

                    this._Value = text.Trim();
                }
            }
            /// <summary>
            /// Přidá do sebe další Values
            /// </summary>
            /// <param name="values"></param>
            public void AddValues(List<ParserSegmentValue> values)
            {
                if (this._SegmentValues == null)
                    this._SegmentValues = new List<ParserSegmentValue>();
                if (values != null)
                {
                    this._SegmentValues.AddRange(values);
                    string text = "";
                    foreach (ParserSegmentValue value in this._SegmentValues)
                        text += value.Text;
                    text = text.Trim();
                    
                    // Odstranit uvozovky na začátku a na konci:
                    int length = text.Length;
                    if (length >= 2 && text[0] == '\"' && text[length - 1] == '\"')
                        text = text.Substring(1, length - 2);

                    this._Value = text.Trim();
                }
            }
        }
        #endregion
        #region Konstanty, enum
        /// <summary>
        /// Záhlaví souboru ve formátu PB.SRD
        /// </summary>
        public const string SRD_HEADER = "$PBExportHeader$";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release (bez čísla)
        /// </summary>
        public const string SRD_RELEASE = "release ";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 1
        /// </summary>
        public const string SRD_RELEASE1 = "release 1;";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 2
        /// </summary>
        public const string SRD_RELEASE2 = "release 2;";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 3
        /// </summary>
        public const string SRD_RELEASE3 = "release 3;";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 4
        /// </summary>
        public const string SRD_RELEASE4 = "release 4;";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 5
        /// </summary>
        public const string SRD_RELEASE5 = "release 5;";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 6
        /// </summary>
        public const string SRD_RELEASE6 = "release 6;";
        /// <summary>
        /// Záhlaví verze souboru ve formátu PB.SRD release 7
        /// </summary>
        public const string SRD_RELEASE7 = "release 7;";
        private const string SRD_DATAWINDOW = "datawindow";
        private const string SRD_BAND_HEADER = "header";
        private const string SRD_BAND_DETAIL = "detail";
        private const string SRD_BAND_SUMMARY = "summary";
        private const string SRD_BAND_FOOTER = "footer";
        private const string SRD_DATA_TABLE = "table";
        private const string SRD_TABLE_COLUMN = "column";
        private const string SRD_TABLE_RETRIEVE = "retrieve";
        private const string SRD_TABLE_ARGUMENTS = "arguments";
        private const string SRD_GROUP = "group";
        private const string SRD_OBJECT_TEXT = "text";
        private const string SRD_OBJECT_COLUMN = "column";
        private const string SRD_OBJECT_COMPUTE = "compute";
        private const string SRD_OBJECT_LINE = "line";
        private const string SRD_OBJECT_RECTANGLE = "rectangle";
        private const string SRD_OBJECT_HTMLTABLE = "htmltable";
        private const string SRD_OBJECT_HTMLGEN = "htmlgen";
        // private const string SRD_ = "";
        #endregion
        #endregion
    }



    /* 
     * 
     *   Poznámky k načítání reportu z PowerBuilderu:
     *  1. Je třeba exportovat z PBL do SRD. Formát PBL je interní a nečitelný. Co jedna sestava to jeden soubor SRD.
     *  2. Formát SRD dovoluje standardní parsování.
     *  





$PBExportHeader$dw_altern_component_tab.srd
release 7;
datawindow(units=0 timer_interval=0 color=16777215 processing=0 HTMLDW=no print.documentname="" print.orientation = 1 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no )
header(height=356 color="536870912" )
summary(height=12 color="536870912" )
footer(height=0 color="536870912" )
detail(height=88 color="536870912" )
table(column=(type=long updatewhereclause=yes name=dil_cislo_subjektu dbname="dil_cislo_subjektu" )
 column=(type=char(30) updatewhereclause=yes name=dil_reference_subjektu dbname="dil_reference_subjektu" )
 column=(type=char(40) updatewhereclause=yes name=dil_nazev_subjektu dbname="dil_nazev_subjektu" )
 column=(type=long updatewhereclause=yes name=kom_cislo_subjektu dbname="kom_cislo_subjektu" )
 column=(type=char(30) updatewhereclause=yes name=kom_reference_subjektu dbname="kom_reference_subjektu" )
 column=(type=char(40) updatewhereclause=yes name=kom_nazev_subjektu dbname="kom_nazev_subjektu" )
 column=(type=long updatewhereclause=yes name=alt_cislo_subjektu dbname="alt_cislo_subjektu" )
 column=(type=char(30) updatewhereclause=yes name=typ_altern dbname="alt_reference_subjektu" )
 column=(type=char(40) updatewhereclause=yes name=alt_nazev_subjektu dbname="alt_nazev_subjektu" )
 column=(type=long updatewhereclause=yes name=cnt_altern dbname="cnt_altern" )
 column=(type=char(1) updatewhereclause=yes name=typ_altern dbname="typ_altern" )
 column=(type=long updatewhereclause=yes name=alt_used_here dbname="alt_used_here" )
 retrieve="EXEC lcs.nsp_mfr_get_altern_comp @constrElement = :ra_cs" arguments=(("ra_cs", number)) )
group(level=1 header.height=80 trailer.height=12 by=("dil_cislo_subjektu" ) header.color="536870912" trailer.color="536870912" )
text(band=header alignment="2" text="Alternativní komponenty TPV" border="0" color="0" x="1129" y="36" height="92" width="2048"  name=t_4  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="553648127" )
text(band=header alignment="0" text="Datum:" border="0" color="0" x="3954" y="48" height="60" width="174"  name=t_1  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="0" font.pitch="2" font.charset="0" background.mode="1" background.color="553648127" )
compute(band=header alignment="1" expression="today()"border="0" color="0" x="4146" y="48" height="72" width="325" format="dd.mm.yyyy"  name=compute_2  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="0" font.pitch="2" font.charset="0" background.mode="1" background.color="553648127" )
compute(band=header alignment="1" expression="'Strana ' + page() + ' z ' + pageCount()"border="0" color="0" x="3881" y="140" height="72" width="590" format="[general]"  name=compute_3  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="0" font.pitch="2" font.charset="0" background.mode="1" background.color="553648127" )
text(band=header alignment="0" text="Název dílce" border="0" color="0" x="526" y="276" height="56" width="581"  name=dil_nazev_subjektu_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
line(band=header x1="41" y1="352" x2="4480" y2="352"  name=l_1 pen.style="0" pen.width="5" pen.color="0"  background.mode="2" background.color="16777215" )
text(band=header alignment="0" text="Reference" border="0" color="0" x="50" y="276" height="60" width="430"  name=dil_reference_subjektu_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=3 alignment="0" tabsequence=32766 border="0" color="0" x="526" y="4" height="76" width="1870" format="[general]"  name=dil_nazev_subjektu edit.limit=40 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=2 alignment="0" tabsequence=32766 border="0" color="0" x="50" y="4" height="76" width="448" format="[general]"  name=dil_reference_subjektu edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=12 alignment="2" tabsequence=32766 border="0" color="0" x="4256" y="8" height="76" width="210" format="[general]~tif(  alt_used_here > 0 , ~"ANO~", ~"! NE !~" )"  name=alt_used_here edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=11 alignment="0" tabsequence=32766 border="0" color="0" x="4133" y="8" height="76" width="64" format="[general]"  name=typ_altern edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
rectangle(band=detail x="4256" y="0" height="80" width="219"  name=ramec1 visible="1~tif( alt_used_here = 0, 1, 0)"  slideup=allabove brush.hatch="7" brush.color="553582847" pen.style="0" pen.width="9" pen.color="0"  background.mode="2" background.color="16777215" )
column(band=detail id=8 alignment="0" tabsequence=32766 border="0" color="0" x="2583" y="8" height="76" width="471" format="[general]"  name=alt_reference_subjektu edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=9 alignment="0" tabsequence=32766 border="0" color="0" x="3067" y="8" height="76" width="855" format="[general]"  name=alt_nazev_subjektu edit.limit=40 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=10 alignment="1" tabsequence=32766 border="0" color="0" x="3895" y="8" height="76" width="201" format="[general]"  name=cnt_altern edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=5 alignment="0" tabsequence=32766 border="0" color="0" x="1115" y="8" height="76" width="539" format="[general]"  name=kom_reference_subjektu edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=6 alignment="0" tabsequence=32766 border="0" color="0" x="1673" y="8" height="76" width="882" format="[general]"  name=kom_nazev_subjektu edit.limit=40 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
line(band=trailer.1 x1="41" y1="0" x2="4480" y2="0"  name=l_4 pen.style="0" pen.width="5" pen.color="0"  background.mode="2" background.color="16777215" )
line(band=summary x1="41" y1="0" x2="4480" y2="0"  name=l_5 pen.style="0" pen.width="5" pen.color="0"  background.mode="2" background.color="16777215" )
compute(band=footer alignment="0" expression="today()"border="0" color="0" x="1042" y="164" height="68" width="283" format="[general]"  name=date_1  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
line(band=header x1="41" y1="256" x2="4480" y2="256"  name=l_3 pen.style="0" pen.width="5" pen.color="0"  background.mode="2" background.color="16777215" )
line(band=header x1="41" y1="244" x2="4480" y2="244"  name=l_2 pen.style="0" pen.width="5" pen.color="0"  background.mode="2" background.color="16777215" )
text(band=header alignment="0" text="Položka kusovníku" border="0" color="0" x="1125" y="276" height="56" width="517"  name=kom_reference_subjektu_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header alignment="0" text="Název" border="0" color="0" x="1673" y="276" height="56" width="686"  name=kom_nazev_subjektu_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header alignment="0" text="Alternativa" border="0" color="0" x="2610" y="276" height="56" width="329"  name=alt_reference_subjektu_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header alignment="0" text="Název" border="0" color="0" x="3072" y="276" height="56" width="622"  name=alt_nazev_subjektu_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header alignment="1" text="Použita zde" border="0" color="0" x="4142" y="276" height="56" width="334"  name=alt_used_here_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header alignment="1" text="Poèet výskytù" border="0" color="0" x="3698" y="276" height="56" width="393"  name=cnt_altern_t  font.face="Arial CE" font.height="-9" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
htmltable(border="1" )
htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" )
 
 
 
 
 
 
 
 
 
$PBExportHeader$dw_pruvodka_vp_s_komp_form.srd
release 7;
datawindow(units=0 timer_interval=0 color=16777215 processing=0 HTMLDW=no print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no )
summary(height=0 color="536870912" )
footer(height=0 color="536870912" )
detail(height=80 color="536870912" )
table(column=(type=long updatewhereclause=yes name=product_order_cislo_subjektu dbname="cislo_subjektu" )
 column=(type=char(30) updatewhereclause=yes name=product_order_refer dbname="refer" )
 column=(type=char(30) updatewhereclause=yes name=kk_kk_refer dbname="kk_refer" )
 column=(type=char(80) updatewhereclause=yes name=kk_kk_nazev dbname="kk_nazev" )
 column=(type=char(40) updatewhereclause=yes name=kk_kk_nazev2 dbname="kk_nazev2" )
 column=(type=char(40) updatewhereclause=yes name=kk_kk_nazev3 dbname="kk_nazev3" )
 column=(type=char(30) updatewhereclause=yes name=varianta_varianta_refer dbname="varianta_refer" )
 column=(type=char(30) updatewhereclause=yes name=zakazka_zakazka_refer dbname="zakazka_refer" )
 column=(type=char(30) updatewhereclause=yes name=utvar_utvar_refer dbname="utvar_refer" )
 column=(type=decimal(6) updatewhereclause=yes name=product_order_mnozstvi dbname="mnozstvi" )
 column=(type=char(30) updatewhereclause=yes name=mj_mj_refer dbname="mj_refer" )
 column=(type=char(30) updatewhereclause=yes name=sklad_odvedeni_sklad_odvedeni dbname="sklad_odvedeni" values="POLOTOVARY	-/HOTOVCI	H/KOOP	X/" )
 column=(type=datetime updatewhereclause=yes name=product_order_datum dbname="datum" )
 column=(type=datetime updatewhereclause=yes name=product_order_datum_end dbname="datum_end" )
 column=(type=long updatewhereclause=yes name=op_op_line dbname="op_line" )
 column=(type=char(40) updatewhereclause=yes name=op_op_nazev dbname="op_nazev" )
 column=(type=char(40) updatewhereclause=yes name=prac_op_pracoviste_nazev dbname="op_pracoviste_nazev" )
 column=(type=decimal(6) updatewhereclause=yes name=op_op_cas dbname="op_cas" )
 column=(type=long updatewhereclause=yes identity=yes name=op_op_nonsubjekt dbname="op_nonsubjekt" )
 column=(type=long updatewhereclause=yes name=kus_kus_line dbname="kus_line" )
 column=(type=char(30) updatewhereclause=yes name=komp_komp_reference dbname="komp_reference" )
 column=(type=char(80) updatewhereclause=yes name=komp_komp_nazev dbname="komp_nazev" )
 column=(type=decimal(18) updatewhereclause=yes name=kus_qty dbname="qty" )
 column=(type=char(30) updatewhereclause=yes name=mj_komp_komp_mj_refer dbname="komp_mj_refer" )
 column=(type=char(30) updatewhereclause=yes name=sklad_kus_skald_kus_refer dbname="skald_kus_refer" )
 column=(type=char(1) updatewhereclause=yes name=prefix dbname="prefix" values="POLOTOVARY	-/HOTOVCI	H/KOOP	X/" )
 column=(type=decimal(6) updatewhereclause=yes name=qty_for_po dbname="qty_for_po" )
 column=(type=char(3) updatewhereclause=yes name=dodavatel_ref dbname="dodavatel_ref" )
 column=(type=char(100) updatewhereclause=yes name=organizace_nazev dbname="organizace_nazev" )
 column=(type=char(40) updatewhereclause=yes name=zakazka_nazev dbname="zakazka_nazev" )
 column=(type=decimal(6) updatewhereclause=yes name=qty_remain dbname="qty_remain" )
 column=(type=char(32766) updatewhereclause=no name=org_poznamka dbname="org_poznamka" )
 column=(type=char(512) updatewhereclause=yes name=note dbname="note" )
 retrieve="SELECT 
lcs.product_order.cislo_subjektu,
lcs.product_order.reference_subjektu refer,
kk.reference_subjektu kk_refer,
kk.nazev_subjektu kk_nazev,
kk.alternativni_nazev2 kk_nazev2,
kk.alternativni_nazev3 kk_nazev3,
varianta.reference_subjektu varianta_refer,
zakazka.reference_subjektu zakazka_refer,
utvar.reference_subjektu utvar_refer,
lcs.product_order.qty mnozstvi,
mj.reference_subjektu mj_refer,
sklad_odvedeni.reference_subjektu sklad_odvedeni,
lcs.product_order.date_doc datum,
lcs.product_order.date_end_plan datum_end,
op.line op_line,
op.op_name op_nazev,
prac.nazev_subjektu op_pracoviste_nazev,
op.time_oper*60 op_cas,
op.cislo_nonsubjektu op_nonsubjekt,
kus.line kus_line,
komp.reference_subjektu komp_reference,
komp.nazev_subjektu komp_nazev,
(kus.qty / lcs.product_order.qty_source) qty,
mj_komp.reference_subjektu komp_mj_refer,
sklad_kus.reference_subjektu skald_kus_refer,
substring(lcs.product_order.reference_subjektu,3,1) as prefix,
(kus.qty ) as qty_for_po,
substring(dodavatel_sub.reference_subjektu,1,3) as dodavatel_ref,
org.nazev_subjektu organizace_nazev,
zakazka.nazev_subjektu zakazka_nazev,
(kus.qty - kus.qty_real) qty_remain,
org.poznamka org_poznamka,
lcs.product_order.note
FROM lcs.product_order 
LEFT OUTER JOIN lcs.kmenova_karta_skladu kk ON kk.cislo_subjektu = lcs.product_order.source
LEFT OUTER JOIN lcs.subjekty mj ON mj.cislo_subjektu = kk.merna_jednotka
LEFT OUTER JOIN lcs.subjekty varianta ON varianta.cislo_subjektu = lcs.product_order.variation
LEFT OUTER JOIN lcs.subjekty zakazka ON zakazka.cislo_subjektu = lcs.product_order.order_relation
LEFT OUTER JOIN lcs.subjekty utvar ON utvar.cislo_subjektu = lcs.product_order.department
LEFT OUTER JOIN lcs.subjekty sklad_odvedeni ON sklad_odvedeni.cislo_subjektu = lcs.product_order.stock
LEFT OUTER JOIN lcs.product_order_operation op ON op.product_order = lcs.product_order.cislo_subjektu
LEFT OUTER JOIN lcs.subjekty prac ON prac.cislo_subjektu = op.workplace
LEFT OUTER JOIN lcs.product_order_structure kus ON kus.operation_po = op.cislo_nonsubjektu and kus.product_order = lcs.product_order.cislo_subjektu
LEFT OUTER JOIN lcs.kmenova_karta_skladu komp ON komp.cislo_subjektu = kus.source
LEFT OUTER JOIN lcs.subjekty mj_komp ON mj_komp.cislo_subjektu = komp.merna_jednotka
LEFT OUTER JOIN lcs.subjekty sklad_kus ON sklad_kus.cislo_subjektu = kus.stock
LEFT OUTER JOIN lcs.stav_sk stav ON stav.zdroj = kus.source AND stav.sklad = kus.stock
LEFT OUTER JOIN lcs.subjekty dodavatel_sub ON dodavatel_sub.cislo_subjektu = stav.aktualni_dodavatel
LEFT OUTER JOIN lcs.vztahysubjektu vzs1 ON vzs1.cislo_subjektu = lcs.product_order.cislo_subjektu AND vzs1.cislo_vztahu = 100083
LEFT OUTER JOIN lcs.organizace org ON org.cislo_subjektu = vzs1.cislo_vztaz_subjektu
WHERE lcs.product_order.cislo_subjektu =  :cislo_subjektu
ORDER BY lcs.product_order.reference_subjektu, op.line, skald_kus_refer desc, komp_reference" arguments=(("cislo_subjektu", number)) )
group(level=1 header.height=676 trailer.height=568 by=("product_order_cislo_subjektu" ) newpage=yes header.color="536870912" trailer.color="536870912" )
group(level=2 header.height=100 trailer.height=72 by=("op_op_nonsubjekt" ) header.color="536870912" trailer.color="536870912" )
text(band=header.1 alignment="2" text="Průvodka výrobního příkazu:" border="0" color="0" x="1874" y="8" height="64" width="873"  name=product_order_cislo_subjektu_t  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="Výrobek:" border="0" color="0" x="41" y="112" height="64" width="293"  name=kk_kk_refer_t  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Var:" border="0" color="0" x="2043" y="112" height="64" width="119"  name=varianta_varianta_refer_t  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Sklad odvedení:" border="0" color="0" x="2414" y="112" height="64" width="549"  name=op_op_line_t  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=2 alignment="1" tabsequence=32766 border="0" color="0" x="2757" y="4" height="96" width="544" format="[general]"  name=product_order_refer edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=3 alignment="0" tabsequence=32766 border="0" color="0" x="329" y="100" height="84" width="585" format="[general]"  name=kk_kk_refer edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=4 alignment="0" tabsequence=32766 border="0" color="0" x="937" y="112" height="64" width="1093" format="[general]"  name=kk_kk_nazev edit.limit=80 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=7 alignment="0" tabsequence=32766 border="0" color="0" x="2176" y="112" height="64" width="224" format="[general]"  name=varianta_varianta_refer edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=12 alignment="0" tabsequence=32766 border="0" color="0" x="2976" y="112" height="64" width="325" format="[general]"  name=sklad_odvedeni_sklad_odvedeni_1 ddlb.limit=0 ddlb.allowedit=no ddlb.case=any  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="čas operace" border="0" color="0" x="1938" y="384" height="64" width="402"  name=t_12  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="Operace" border="0" color="0" x="46" y="384" height="64" width="256"  name=t_1  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Pracoviště" border="0" color="0" x="466" y="384" height="64" width="366"  name=t_2  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Skutečný čas" border="0" color="0" x="2793" y="384" height="64" width="439"  name=t_13  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="Komponenta" border="0" color="0" x="41" y="512" height="64" width="402"  name=t_14  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="Mn. na VP" border="0" color="0" x="2958" y="508" height="64" width="343"  name=t_18  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="Popis" border="0" color="0" x="535" y="512" height="64" width="206"  name=t_28  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="-----------------------------------------------------------------------------------------" border="0" color="0" x="41" y="444" height="64" width="3259"  name=t_7  font.face="Courier New CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="-----------------------------------------------------------------------------------------" border="0" color="0" x="41" y="336" height="64" width="3259"  name=t_20  font.face="Courier New CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="-----------------------------------------------------------------------------------------" border="0" color="0" x="41" y="568" height="64" width="3259"  name=t_19  font.face="Courier New CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="Datum:" border="0" color="0" x="1833" y="272" height="64" width="219"  name=t_8  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Ukončení:" border="0" color="0" x="2514" y="272" height="64" width="334"  name=t_9  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=13 alignment="0" tabsequence=32766 border="0" color="0" x="2062" y="272" height="64" width="443" format="dd.mm.yyyy"  name=product_order_datum_1 edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=14 alignment="0" tabsequence=32766 border="0" color="0" x="2857" y="272" height="64" width="443" format="dd.mm.yyyy"  name=product_order_datum_end_1 edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Zak:" border="0" color="0" x="1934" y="192" height="64" width="151"  name=zakazka_zakazka_refer_t  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=30 alignment="0" tabsequence=32766 border="0" color="0" x="2555" y="192" height="68" width="750" format="[general]"  name=zakazka_nazev edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=8 alignment="0" tabsequence=32766 border="0" color="0" x="2094" y="192" height="64" width="448" format="[general]"  name=zakazka_zakazka_refer edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="Pro:" border="0" color="0" x="41" y="192" height="64" width="146"  name=t_24  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=29 alignment="0" tabsequence=32766 border="0" color="0" x="210" y="192" height="64" width="1595" format="[general]"  name=organizace_nazev edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="0" text="Množství:" border="0" color="0" x="46" y="276" height="64" width="329"  name=t_5  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.1 id=10 alignment="0" tabsequence=32766 border="0" color="0" x="389" y="264" height="96" width="457" format="#,##0.00"  name=product_order_mnozstvi_1 edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="Zbývá vydat" border="0" color="0" x="2528" y="512" height="64" width="315"  name=t_29  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="1" text="Mn.jedn." border="0" color="0" x="2062" y="512" height="64" width="311"  name=t_16  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="MJ" border="0" color="0" x="2386" y="512" height="64" width="101"  name=t_17  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="Dod." border="0" color="0" x="1920" y="512" height="64" width="146"  name=t_23  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="/" border="0" color="0" x="1861" y="512" height="64" width="46"  name=t_22  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.1 alignment="2" text="Sklad" border="0" color="0" x="1646" y="512" height="64" width="201"  name=t_15  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.2 alignment="0" text="-----------------------------------------------------------------------------------------" border="0" color="0" x="41" y="48" height="64" width="3255"  name=t_3  font.face="Courier New CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.2 id=18 alignment="1" tabsequence=32766 border="0" color="0" x="1819" y="4" height="64" width="329" format="#,##0.00"  name=op_op_cas edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.2 alignment="1" text="-" border="0" color="0" x="352" y="4" height="64" width="41"  name=t_10  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.2 alignment="1" text="Skut.čas: .   .   .   .   .   ." border="0" color="0" x="2322" y="4" height="64" width="955"  name=t_11  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.2 id=16 alignment="1" tabsequence=32766 border="0" color="0" x="41" y="4" height="64" width="293" format="[general]"  name=op_op_nazev edit.limit=40 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=header.2 id=17 alignment="0" tabsequence=32766 border="0" color="0" x="571" y="4" height="64" width="855" format="[general]"  name=prac_op_pracoviste_nazev edit.limit=40 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=header.2 alignment="0" text="Min." border="0" color="0" x="2162" y="4" height="64" width="146"  name=t_6  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="2" background.color="16777215" )
column(band=header.2 id=15 alignment="0" tabsequence=32766 border="0" color="0" x="407" y="4" height="64" width="146" format="[general]"  name=op_op_line edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=27 alignment="1" tabsequence=32766 border="0" color="0" x="2958" y="4" height="64" width="329" format="#,##0.00"  name=qty_for_po edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=21 alignment="0" tabsequence=32766 border="0" color="0" x="41" y="4" height="64" width="553" format="[general]"  name=komp_komp_reference edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=22 alignment="0" tabsequence=32766 border="0" color="0" x="603" y="4" height="64" width="1083" format="[general]"  name=komp_komp_nazev edit.limit=80 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=detail alignment="0" text="-----------------------------------------------------------------------------------------" border="0" color="0" x="37" y="136" height="64" width="3264"  name=t_4  font.face="Courier New CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=23 alignment="1" tabsequence=32766 border="0" color="0" x="2075" y="4" height="64" width="329" format="#,##0.00"  name=kus_qty edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=detail alignment="2" text="/" border="0" color="0" x="1865" y="4" height="64" width="46"  name=t_21  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="2" background.color="16777215" )
column(band=detail id=24 alignment="0" tabsequence=32766 border="0" color="0" x="2423" y="4" height="64" width="165" format="[general]"  name=mj_komp_komp_mj_refer edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=25 alignment="1" tabsequence=32766 border="0" color="0" x="1710" y="4" height="64" width="142" format="[general]"  name=sklad_kus_skald_kus_refer edit.limit=30 edit.case=any edit.autoselect=yes edit.autohscroll=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=28 alignment="0" tabsequence=32766 border="0" color="0" x="1925" y="4" height="64" width="133" format="[general]"  name=dodavatel_ref edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
column(band=detail id=31 alignment="1" tabsequence=32766 border="0" color="0" x="2606" y="4" height="64" width="329" format="#,##0.00"  name=qty_remain edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=trailer.1 alignment="0" text="---------------------------------------------------------------" border="0" color="0" x="87" y="188" height="88" width="3191"  name=t_27  font.face="Courier New CE" font.height="-14" font.weight="700"  font.family="1" font.pitch="1" font.charset="238" background.mode="1" background.color="536870912" )
column(band=trailer.1 id=33 alignment="0" tabsequence=32766 border="0" color="0" x="91" y="92" height="64" width="3191" format="[general]"  name=note edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
column(band=trailer.1 id=32 alignment="0" tabsequence=32766 border="0" color="0" x="91" y="20" height="64" width="3191" format="[general]"  name=org_poznamka edit.limit=0 edit.case=any edit.autoselect=yes  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
compute(band=trailer.1 alignment="0" expression="year( today() )"border="0" color="0" x="590" y="324" height="92" width="297" format="[GENERAL]"  name=compute_1  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=trailer.1 alignment="0" text=".       ." border="0" color="0" x="297" y="324" height="92" width="206"  name=t_30  font.face="Arial CE" font.height="-14" font.weight="700"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=trailer.1 alignment="0" text="kontrola" border="0" color="0" x="2848" y="432" height="64" width="238"  name=t_26  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
text(band=trailer.1 alignment="0" text="Datum ukončení" border="0" color="0" x="251" y="432" height="64" width="471"  name=t_25  font.face="Arial CE" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="238" background.mode="1" background.color="536870912" )
htmltable(border="1" )
htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" )
  
 
 
 
    */
}
